package com.longcai.piaojia.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;

import com.longcai.piaojia.R;
import com.longcai.piaojia.adapter.ProblemsAdapter;
import com.longcai.piaojia.conn.ProblemsListGet;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.http.AsyCallBack;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/11/4.
 */
public class ProblemsActivity extends BaseActivity {


    @BoundView(R.id.problems_elv) private ExpandableListView problems_elv;

//    private List<List<ChildEntity>> childList = new ArrayList<>();
//    private List<GroupList> groupList = new ArrayList<>();

    private List<ProblemsListGet.ProblemEntity> childList = new ArrayList<>();
    private ProblemsAdapter adapter;


    private ProblemsListGet problemsListGet = new ProblemsListGet(new AsyCallBack<List<ProblemsListGet.ProblemEntity>>(){

        @Override
        public void onSuccess(String toast, int type, List<ProblemsListGet.ProblemEntity> problemEntities) throws Exception {

            childList.addAll(problemEntities);
            adapter.notifyDataSetChanged();

        }

        @Override
        public void onFail(String toast, int type) throws Exception {


        }

    });
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_problems);

        setBackTrue();

        setTitleName(getString(R.string.mine_problems_text));

        problems_elv.setDivider(null);

        problems_elv.setGroupIndicator(null);

        problems_elv.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {

                if (parent.isGroupExpanded(groupPosition)) {
                    parent.collapseGroup(groupPosition);
                } else {
                    //第二个参数false表示展开时是否触发默认滚动动画
                    parent.expandGroup(groupPosition, false);
                }
                //telling the listView we have handled the group click, and don't want the default actions.
                return true;

            }
        });

        problems_elv.setAdapter(adapter = new ProblemsAdapter(context, childList));

        problemsListGet.execute(this);

    }



}
